/*******************************************************************************
Replication Materials for Blau, Kahn, Brummund, Cook, and Larson-Koester "Is 
There Still Son Preference in the United States?"

Table R7, Age at First Birth Control (Table 4 Fertility Regressions)

Date Modified: 10/19/2019

*******************************************************************************/

*Define needed variables
local v "head_samp secgen imm_gen core_samp core_sampf citizen"
local v "`v' hhwtnorm lths scol cold sp_lths sp_scol sp_cold genrace sp_genrace"
local v "`v' region year age* sp_age* chld1 gt0chld femhdalt nchild c_age1"

*Load Data
use `v' using "$cps\regfile_March_core", clear

*Keep only those who are a household head or spouse of the household head
keep if head_samp == 1

label var chld1 "First Child Girl"

*Gen Mother Age at First Birth
gen age_fb = .
replace age_fb = age - c_age1 if c_age1!=.

/*******************************************************************************

I. Natives

*******************************************************************************/

*Original

local sample "if imm_gen==3 & citizen!=1 & gt0chld==1 & core_sampf==1"

local wgt "hhwtnorm"

local controls "lths scol cold sp_lths sp_scol sp_cold" 
local controls "`controls' i.genrace i.sp_genrace i.region i.year age age2 age3" 
local controls "`controls' sp_age sp_age2 sp_age3" 

local main "chld1"

reg nchild `main' `controls' `sample' [aw=`wgt'], robust
qui sum nchild `sample'  [aw=`wgt']
local dep_mean : display %9.4f r(mean)
local pct_effect : display %9.4f (_b[chld1]/r(mean))*100
outreg2 using "$routput\Table R7.xls", keep(`main') title("Table R7: Effects of Female First Child on Fertility by Immigrant Generation (Table 4 Control for Age at First Birth)") ctitle(3rd+ gen) addtext(Mean, `dep_mean', Pct. Effect, `pct_effect', Age at First Birth Control, "No [orig.]") label dec(4) nocons nor2 replace


*With AFB Control

local sample "if imm_gen==3 & citizen!=1 & gt0chld==1 & core_sampf==1"

local wgt "hhwtnorm"

local controls "`controls' age_fb" 

local main "chld1"

reg nchild `main' `controls' `sample' [aw=`wgt'], robust
qui sum nchild `sample'  [aw=`wgt']
local dep_mean : display %9.4f r(mean)
local pct_effect : display %9.4f (_b[chld1]/r(mean))*100
outreg2 using "$routput\Table R7.xls", keep(`main') ctitle(3rd+ gen) addtext(Mean, `dep_mean', Pct. Effect, `pct_effect', Age at First Birth Control, "Yes") label dec(4) nocons nor2 append



/*******************************************************************************

II. Immigrants

*******************************************************************************/

*Original

local sample "if imm_gen==1 & citizen!=1 & gt0chld==1 & core_sampf==1"

local wgt "hhwtnorm"

local controls "lths scol cold sp_lths sp_scol sp_cold" 
local controls "`controls' i.genrace i.sp_genrace i.region i.year age age2 age3" 
local controls "`controls' sp_age sp_age2 sp_age3" 

local main "chld1"

reg nchild `main' `controls' `sample' [aw=`wgt'], robust
qui sum nchild `sample'  [aw=`wgt']
local dep_mean : display %9.4f r(mean)
local pct_effect : display %9.4f (_b[chld1]/r(mean))*100
outreg2 using "$routput\Table R7.xls", keep(`main') ctitle(1st gen) addtext(Mean, `dep_mean', Pct. Effect, `pct_effect', Age at First Birth Control, "No [orig.]") label dec(4) nocons nor2 append

*With AFB Control

local sample "if imm_gen==1 & citizen!=1 & gt0chld==1 & core_sampf==1"

local wgt "hhwtnorm"

local controls "`controls' age_fb" 

local main "chld1"

reg nchild `main' `controls' `sample' [aw=`wgt'], robust
qui sum nchild `sample'  [aw=`wgt']
local dep_mean : display %9.4f r(mean)
local pct_effect : display %9.4f (_b[chld1]/r(mean))*100
outreg2 using "$routput\Table R7.xls", keep(`main') ctitle(1st gen) addtext(Mean, `dep_mean', Pct. Effect, `pct_effect', Age at First Birth Control, "Yes") label dec(4) nocons nor2 append

/*******************************************************************************

III. Second Generation

*******************************************************************************/

*Original

local sample "if imm_gen==2 & citizen!=1 & gt0chld==1 & core_sampf==1"

local wgt "hhwtnorm"

local controls "lths scol cold sp_lths sp_scol sp_cold" 
local controls "`controls' i.genrace i.sp_genrace i.region i.year age age2 age3" 
local controls "`controls' sp_age sp_age2 sp_age3" 

local main "chld1"

reg nchild `main' `controls' `sample' [aw=`wgt'], robust
qui sum nchild `sample'  [aw=`wgt']
local dep_mean : display %9.4f r(mean)
local pct_effect : display %9.4f (_b[chld1]/r(mean))*100
outreg2 using "$routput\Table R7.xls", keep(`main') ctitle(2nd gen) addtext(Mean, `dep_mean', Pct. Effect, `pct_effect', Age at First Birth Control, "No [orig.]") label dec(4) nocons nor2 append


*With AFB Control

local sample "if imm_gen==2 & citizen!=1 & gt0chld==1 & core_sampf==1"

local wgt "hhwtnorm"

local controls "`controls' age_fb" 

local main "chld1"

reg nchild `main' `controls' `sample' [aw=`wgt'], robust
qui sum nchild `sample'  [aw=`wgt']
local dep_mean : display %9.4f r(mean)
local pct_effect : display %9.4f (_b[chld1]/r(mean))*100
outreg2 using "$routput\Table R7.xls", keep(`main') ctitle(2nd gen) addtext(Mean, `dep_mean', Pct. Effect, `pct_effect', Age at First Birth Control, "Yes") label dec(4) nocons nor2 append

